﻿<?xml version="1.0" encoding="utf-8"?>
<xsd:schema targetNamespace="http://schemas.microsoft.com/dynamics/2011/01/documents/Message" 
            xmlns:tns="http://schemas.microsoft.com/dynamics/2011/01/documents/Message" 
            xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
            elementFormDefault="qualified">
	
	<xsd:element name="Envelope" type="tns:EnvelopeType"/>
	<xsd:element name="MessageParts" type="tns:MessagePartsType"/>

	<xsd:complexType name="EnvelopeType">
		<xsd:annotation>
			<xsd:documentation xml:lang="en-us">Envelope of the message.</xsd:documentation>
		</xsd:annotation>
		<xsd:sequence>
            <xsd:element name="Header" type="tns:HeaderType"/>
            <xsd:element name="Body" type="tns:BodyType"/>
        </xsd:sequence> 
    </xsd:complexType>
    
    <xsd:complexType name="HeaderType">
		<xsd:annotation>
			<xsd:documentation xml:lang="en-us">Header containing message metadata.</xsd:documentation>
		</xsd:annotation>
		<xsd:sequence>          
            <xsd:element name="MessageId" type="xsd:string" minOccurs="0"/>
            <xsd:element name="LogonAsUser" type="xsd:string" minOccurs="0"/>
            <xsd:element name="PartitionKey" type="xsd:string" minOccurs="0"/>
            <xsd:element name="Company" type="xsd:string" minOccurs="0"/>
            <xsd:element name="Action" type="xsd:string"/>
            <xsd:element name="ConversationId" type="tns:ConversationIdType" minOccurs="0"/>
            <xsd:element name="RequestMessageId" type="xsd:string" minOccurs="0"/>
        </xsd:sequence>
    </xsd:complexType>

	<xsd:complexType name="BodyType">
		<xsd:annotation>
			<xsd:documentation xml:lang="en-us">Body of the message.</xsd:documentation>
		</xsd:annotation>
		<xsd:sequence>
			<xsd:element name="MessageParts" type="tns:MessagePartsType"/>
		</xsd:sequence>
	</xsd:complexType>

	<xsd:simpleType name="ConversationIdType">
		<xsd:annotation>
			<xsd:documentation xml:lang="en-us">Conversation identifier of the message.</xsd:documentation>
		</xsd:annotation>
		<xsd:restriction base="xsd:string">
			<xsd:minLength value="1"/>
			<xsd:maxLength value="256"/>
		</xsd:restriction>
	</xsd:simpleType>

	<xsd:complexType name="MessagePartsType">
		<xsd:annotation>
			<xsd:documentation xml:lang="en-us">Zero or more parts of the message.</xsd:documentation>
		</xsd:annotation>
		<xsd:sequence>
			<xsd:any namespace="##any" processContents="skip"/>
		</xsd:sequence>
	</xsd:complexType>

</xsd:schema>